package com.github.data_manage.dao

import com.github.data_manage.domain.po.FundDepthResearchAttach
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param
import java.time.LocalDate

/**
 *
 * @author chenhainan
 * @since 2025/8/11
 */
interface FundDepthResearchAttachDao : BaseDao<FundDepthResearchAttach> {

    fun findByFundIdEqualsAndDataMonthEquals(fundId: Int, dataMonth: LocalDate): FundDepthResearchAttach?

    @Query("select f from FundDepthResearchAttach f where f.fundId=:fundId order by f.dataMonth desc ")
    fun findAllByFundIdIs(@Param("fundId") fundId: Int): List<FundDepthResearchAttach>


    fun findAllByFundIdAndDataMonthBetween(
        fundId: Int,
        startDate: LocalDate,
        endDate: LocalDate
    ): List<FundDepthResearchAttach>

    @Query(
        """
        select *
        from t_fund_depth_research_attach
        where fund_id = :fundId and YEAR(data_month) = :dataYear and MONTH(data_month) = 12
    """, nativeQuery = true
    )
    fun findFundYearLastMonthData(
        @Param("fundId") fundId: Int,
        @Param("dataYear") year: Int
    ): FundDepthResearchAttach?
}